home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / btrees2.arc / BTUSE.C < prev    next >
Text File  |  1984-12-14  |  2KB  |  80 lines

  1. /*    sample user program to test btsys     */
  2.  
  3.     struct {
  4.         unsigned fcode;
  5.         unsigned keylen;
  6.         unsigned filhand;
  7.         unsigned datapt;
  8.         char    filkey[17];
  9.         char    filnam[15];
  10.         }    btstruct, *structp = &btstruct;
  11.  
  12. main ()
  13.  
  14. {
  15.     int    code, number;
  16.     char    literal[17];
  17.     int    retcode;
  18.  
  19. do    {
  20.     printf ("enter function code\n");
  21.     scanf ("%d", &code);
  22.     switch (code)    {
  23.  
  24.     case 0 :    /* initialize system    */
  25.         structp->fcode = code;
  26.         retcode = btfunc (structp);
  27.         break;
  28.     case 1 :    /* file create */
  29.     case 2 :    /* file open */
  30.         printf ("enter file name\n");
  31.         scanf ("%s", literal);
  32.         strcpy (structp->filnam, literal);
  33.         printf ("enter keylength\n");
  34.         scanf ("%d", &number);
  35.         structp->keylen = number;
  36.         structp->fcode = code;
  37.         retcode = btfunc (structp);
  38.         printf ("retcode %d filhand %d\n",
  39.             retcode, structp->filhand);
  40.         break;
  41.     case 3 :    /* file close */
  42.         printf ("enter file handle\n");
  43.         scanf ("%d", &number);
  44.         structp->filhand = number;
  45.         structp->fcode = code;
  46.         retcode = btfunc (structp);
  47.         printf ("retcode %d from close\n", retcode);
  48.         break;
  49.     case 4 :    /* insert keys */
  50.         printf ("enter file handle\n");
  51.         scanf ("%d", &number);
  52.         structp->filhand = number;
  53.         printf ("enter key\n");
  54.         scanf ("%s", literal);
  55.         strcpy (structp->filkey, literal);
  56.         printf ("enter data pointer\n");
  57.         scanf ("%d", &number);
  58.         structp->datapt = number;
  59.         structp->fcode = code;
  60.         retcode = btfunc (structp);
  61.         printf ("retcode %d from insert\n", retcode);
  62.         break;
  63.     case 5 :    /* random read */
  64.         printf ("enter file handle\n");
  65.         scanf ("%d", &number);
  66.         structp->filhand = number;
  67.         printf ("enter key\n");
  68.         scanf ("%s", literal);
  69.         strcpy (structp->filkey, literal);
  70.         structp->fcode = code;
  71.         retcode = btfunc (structp);
  72.         printf ("retcode %d key %s datapt %d\n",
  73.             retcode, structp->filkey, structp->datapt);
  74.         break;
  75.     default : break;
  76.     }    /* end switch */
  77. } while (code != -1);/* end while */
  78.  
  79. }    /* end btuse */
  80.